package org.web.project.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.utils.AjaxResult;
import org.web.project.domain.Project;
import org.web.project.service.ProjectService;

import java.util.List;

@RestController
@RequestMapping("/project/*")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @GetMapping("list")
    public AjaxResult list(){
        return AjaxResult.success(projectService.list());
    }

    @GetMapping("listByPid/{pid}")
    public AjaxResult listByPid(@PathVariable Long pid){
        return AjaxResult.success(projectService.selectByPid(pid));
    }
    @GetMapping("listByPids")
    public AjaxResult listByPids(@RequestBody List<Long> pids){
        return AjaxResult.success(projectService.listByIds(pids));
    }
    @GetMapping("listByLikeName")
    public AjaxResult listByLikeName(@RequestParam String name){
        return AjaxResult.success(projectService.selectByLikeName(name));
    }
    @PostMapping("add")
    public AjaxResult add(@RequestBody Project project){
        boolean save = projectService.save(project);
        if (save){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}
